import time
import unittest
import json
from api.employee import EmployeeApi
from api.login import LoginApi
from parameterized import parameterized

# 获取token
class GetToken(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.login_api = LoginApi()
    def test_success(self):
        response =self.login_api.login({
            'mobile':'13800000002',
            'password':'123456'
            }
        )
        result = response.json()
        self.assertEqual(10000,result.get('code'))
        if result.get('code') == 10000 and '操作成功！' in result.get('message'):
            with open('./data/token.text','w',encoding='utf-8') as f:
                f.write(result.get('data'))

# def build_data():
#     file = './data/employee_data.json'
#     test_data=[]
#     with open(file,'r',encoding='utf-8') as f:
#         json_data =json.load(f)




class Text_Employee(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.employee = EmployeeApi()
    def test_employee(self):
        # 增加
        response = self.employee.add_employee({
            'username':'耿瑞牛逼7',
            'mobile':'15210837639',
            'workNumber':'15773'
        })
        json_data = response.json()
        self.assertEqual(200,response.status_code)
        self.assertEqual(True,json_data.get('success'))
        self.assertEqual(10000,json_data.get('code'))
        self.assertIn('操作成功',json_data.get('message'))
        data = json_data.get('data')
        if data:
            self.assertEqual('ok',json_data.get('id'))
        # employee_id = data.get('id')
        # 查询
        # response1 = self.employee.url_get(employee_id)
        # json_data1 = response1.json()
        # self.assertEqual(200, response1.status_code)
        # self.assertEqual(True, json_data1.get('success'))
        # self.assertEqual(10000, json_data1.get('code'))
        # self.assertEqual('操作成功', json_data1.get('message'))
        # # # 删除
        # response1 = self.employee.del_employee(employee_id)
        # json_data1 = response1.json()
        # self.assertEqual(200, response1.status_code)
        # self.assertEqual(True, json_data1.get('success'))
        # self.assertEqual(10000, json_data1.get('code'))
        # self.assertEqual('操作成功', json_data1.get('message'))